<?php

class IndexAction extends CommonAction
{
	
	public function index() {
		if($this->isLogin){
			$this->_init_user_info();
		}
		
		# 日历
		$calendar = $this->_calendar();
		$this->assign('_calendar', $calendar);
		
		# 本月本日
		$this->assign('_month', date('m', time()));
		$this->assign('_day', date('d', time()));
		
		# 奖品领取
		$satisfy_prize = A('Satisfy')->showPrize();
		$this->assign('_satisfy_prize', $satisfy_prize);
		
		# 抽奖
		$lotto_prize = A('Lotto')->_getAllForIndex();
		$this->assign('_lotto_prize', $lotto_prize);
		
		# 活动动态~即抽奖记录
		$record_lotto = $this->_dynamic();
		$this->assign('_record_lotto', $record_lotto);
		
		# 拍卖展示
		$auction = $this->_auction();
		$this->assign('_auction', $auction);
		
		# 看视频新增金币
		$key = $this->_addGoldForMedia();
		$this->assign('_key', $key);
		$_iskey = $key ? 1 : 0 ;
		$this->assign('_iskey', $_iskey);
		
		$this->display();
	}

	private function _init_user_info(){
		
		# 打卡记录
		$cardlist = $this->_cardList();
		$this->assign('_cardlist', $cardlist);
		
	}
	
	
	
	# 拍卖展示
	private function _auction(){
		$auction_prize[1] = A('Auction')->_getByPeriod(1);
		$auction_prize[2] = A('Auction')->_getByPeriod(2);
		$auction_prize[3] = A('Auction')->_getByPeriod(3);
		$auction_prize[4] = A('Auction')->_getByPeriod(4);
		$_time = time();
		$_show = 1;
		foreach($auction_prize as $k=>$v){ # lock 为-1 不显示，为0或者1 显示 | lock 为1的时候允许竞拍，为0或者-1不允许
			if($_time >= $v[0]['au_etime']){
				$lock[$k] = -1;
			}else{
				if($_time >= $v[0]['au_stime']){
					$lock[$k] = $_show;
					unset($_show);
					if(date('Y-m-d',time()) == date('Y-m-d', $v[0]['au_etime'])){
						$_downtime = 1;
					}
				}else{
					if(isset($_show)){
						$lock[$k] = 0;
						unset($_show);
					}else{
						$lock[$k] = -2;
					}
				}
			}
		}  # 建立在每个拍卖周期不重合，周期从前到后的基础上。 
		
		return array('auction_prize'=>$auction_prize, 'lock'=>$lock, '_downtime' => $_downtime);
	}
	
	# 动态
	private function _dynamic(){
		$list = D('Record')->getLottoDynamic();
		return $list;
	}
	
	
	# 打卡记录
	private function _cardList(){
		$cardlist['7'] = A('Card')->cardList('2012-07');
		$cardlist['8'] = A('Card')->cardList('2012-08');
		foreach($cardlist as $key=>$val){
			foreach($val as $k=>$v){
				$list[$key][intval(substr($v['ucd_date'], 8))] = true;
			}
		}
		return $list;
	}
	
	
	# 日历
	private function _calendar(){
		$calendar = array(
					'7' => array(),
					'8' => array(0,0,0)
		);
		
		for($i=1; $i<=31; $i++){
			$calendar['7'][] = $i;
		}
		for($i=1; $i<=31; $i++){
			$calendar['8'][] = $i;
		}
		
		foreach($calendar as $key=>$val){
			for($i=count($val)+1; $i<=35; $i++){
				$calendar[$key][] = 0;
			}
		}
		return $calendar;
	}

	# 显示领取奖品
	public function receive(){
		$_spr_id = $_REQUEST['spr_id'];
		$spr = getInfoById('PrizeSatisfy', $_spr_id);
		$this->assign('_spr', $spr);
		$this->display();
	}
	
	private function _addGoldForMedia(){
		return $_REQUEST['key'];
	}
	
	public function prize_infor(){
		# 中奖信息
		$prize = A('Record')->getPrize();
		$this->assign('_prize', $prize);
		$this->display();
	}

}
?>